<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script crossorigin="anonymous" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" src="https://lib.baomitu.com/jquery/3.5.1/jquery.min.js"></script>

    <script>
        $(function(){ //必须写
            $("#btn_login").on("click",function (){
                var url = "/BookUserServlet?action=login";
                //var data = new FormData(document.getElementById("myform"));
                var data = $("#myform").serialize();//封装表单的方法,不能封装上传文件
                console.info(data);
                $.post(url,data,function (resp){
                    if(resp.state==1){
                        alert(resp.msg);
                        location.href="index.jsp";
                    }else{
                        alert(resp.msg);
                    }
                },"json")
            })
        })
    </script>
</head>
<body>
<form id="myform">
    <h1>用户名:<input type="text" name="userName"></h1>
    <h1>密码:<input type="password" name="userPwd"></h1>
    <input type="button" value="登录" id="btn_login">
</form>
</body>
</html>